//个人中心 图片 阅读一篇帖子

// const e = require("express");

//获取postId
let postId = document.location.href.split('=')[1]
var bigone = document.getElementsByClassName('bigone')[0]
var thumbsup;
var clinvitation;
var invitationviews;
axios({
    method: 'get',
    url: '/read/oneinvitation',
    params: {
        userId: 6,
        postId: postId,
    }
}).then(data => {
    invitationnums()
    invitationcollectnums()
    invitationviews()
    bigone.innerHTML = `<div class="bigoneheader">
    <div class="headtop">
        <div class="headtopimg"><img src="${data.data.data.data.portrait}" alt="">


        </div>
        <div class="headrightusername">${data.data.data.data.userName}</div>
        <div class="headrightdate">${data.data.data.data.time}</div>

        <div class="headtopcontext">${data.data.data.data.context}</div>
    </div>
    <div class="headbottom"></div>
</div>

<div class="bigcontent"><img src='${data.data.data.data.path[0]}'>
</div>
<div class="bigbottom"><span class='thumbsup'>
</span>
<span class='clinvitation'></span>
<span class='invitationviews'></span></div>`
    thumbsup = document.getElementsByClassName('thumbsup')[0]
    clinvitation = document.getElementsByClassName('clinvitation')[0]
    invitationviews = document.getElementsByClassName('invitationviews')[0]

}).catch(err => {
    console.log(err);
    alert('no')
})
var thumbs;
//帖子点赞数量
function invitationnums() {
    axios({
        method: 'get',
        url: '/invitation/nums',
        params: {
            postId: postId,
        }
    }).then(data => {
        thumbsup.innerHTML = `<i class="fa fa-thumbs-o-up"  id='thumbs' onclick="dianzaninvitation(this)" click="invitationstatus(this)"></i>${data.data.data.data}`
        thumbs = document.getElementById('thumbs')
        console.log(thumbs);
        invitationstatus()

    }).catch(err => {
        console.log(err);
        alert('no')
    })
}
// invitationstatus()
//查看帖子点赞状态（1已点赞）
function invitationstatus(th) {
    axios({
        method: 'get',
        url: '/invitation/status',
        params: {
            userId: 6,
            postId: postId
        }
    }).then(data => {
        if (data.data.data.data === 0) {
            th.style.color = 'none'
        } else {
            th.style.color = 'red'
        }
    }).catch(err => {
        console.log(err);
        alert('no')
    })
}

function a(th) {
    console.log(th);
}
//点赞帖子  
function dianzaninvitation(th) {
    console.log(th);
    axios({
        method: 'post',
        url: '/dianzan/invitation',
        params: {
            userId: 6,
            postId: postId
        }
    }).then(data => {
        console.log(data.data);
        console.log(data.data.data.data);
        if (data.data.data.data === 1) {
            th.style.color = 'none'
        } else {
            th.style.color = 'red'
            alert('点赞帖子：点赞成功')

        }

    }).catch(err => {
        console.log(err);
        alert('nononon')
    })
}

//帖子收藏数量
function invitationcollectnums() {
    axios({
        method: 'get',
        url: '/collectnums/invitation',
        params: {
            postId: postId
        }
    }).then(data => {
        clinvitation.innerHTML = `<i class="fa fa-gift"></i>${data.data.data.data}`

    }).catch(err => {
        console.log(err);
        alert('网络开小差啦~')
    })
}

//帖子浏览量
function invitationviews() {
    axios({
        method: 'get',
        url: '/invitation/views',
        params: {
            postId: postId
        }
    }).then(data => {
        invitationviews.innerHTML = `<i class="fa fa-eye">${data.data.data.data}</i>`


    }).catch(err => {
        console.log(err);
        alert('网络开小差啦~')
    })
}